package com.qf.business.redevnlopes.core.controller;

import com.qf.business.redevnlopes.core.service.RedEnvelopesService;
import com.qf.commons.data.result.R;
import com.qf.data.redenvlopes.vo.input.RedEvnlopesInput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author Ken
 * create_time 2022/9/27
 */
@RestController
@RequestMapping("/red")
@EnableScheduling
public class RedEnvlopesController {

    @Autowired
    private RedEnvelopesService redEnvelopesService;

    /**
     * 发送红包
     * @return
     */
    @RequestMapping("/send")
    public R send(RedEvnlopesInput evnlopesInput){
        int redId = redEnvelopesService.sendRed(evnlopesInput);
        return R.create(redId);
    }

    /**
     * 抢红包的请求
     * @return
     */
    @RequestMapping("/rob")
    public R rob(Integer redid){
        // 正数 - 表示抢到的积分数值
        int result = redEnvelopesService.robRed(redid);
        return R.create(result);
    }
}
